package leecode

func findSubsequences(nums []int) (result [][]int) {
	path := make([]int, 0, len(nums))
	var backtracking func(startIndex int)
	backtracking = func(startIndex int) {
		if len(path) > 1 {
			temp := make([]int, len(path))
			copy(temp, path)
			result = append(result, temp)
		}
		used := make(map[int]bool, len(nums))
		for i := startIndex; i < len(nums); i++ {
			//去重
			if used[nums[i]] {
				continue
			}
			if len(path) == 0 || nums[i] >= path[len(path)-1] {
				used[nums[i]] = true
				path = append(path, nums[i])
				backtracking(i + 1)
				path = path[:len(path)-1]
			}
		}
	}
	backtracking(0)
	return
}
